package com.itheima.mapper;

import com.itheima.pojo.Category;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface CategoryMapper {
    @Insert("insert into category(category_name, category_alias, create_user, create_time, update_time) VALUES(#{categoryName},#{categoryAlias},#{createUser},now(),now())")
    void add(Category category);

    @Select("SELECT * FROM category WHERE create_user = #{ID}")
    List<Category> list(Integer id);

    @Select("SELECT * FROM category WHERE id = #{id}")
    Category findById(Integer id);

    @Select("UPDATE category SET category_name=#{categoryName},category_alias=#{categoryAlias},update_time=NOW() where id=#{id}")
    void update(Category category);

    @Delete("delete FROM category WHERE id=#{id}")
    void delete(Integer id);
}
